<?php

include_once("data/dao/CollectionDAO.php");

class CollectionUtils{
	
	/**
	 * checks the database to confirm whether the user
	 * has an existing collection or not.
	 * 
	 * @param int $id
	 * @return boolean
	 */
	public static function userHasACollection($id){
		
		$collectionDAO = new CollectionDAO();
		
		try{
			if($collectionDAO->getCollection($id) != null)
				return true;
		}
		catch(Exception $e){
			return false;
		}	
	}
	
	public static function gameAlreadyOwned($gameID, $userID){
		
		$collectionDAO = new CollectionDAO();
		
		try{
			$collection = $collectionDAO->getCollection($userID);
			if($collection == null)
				return false;
				
			foreach($collection->getGames() as $g){
				if($g == $gameID)
					return true;
			}
		}
		catch(Exception $e){
			return false;
		}
		return false;		
	}
	
	public static function collectionIsEmpty($userId){
		
		$cdao = new CollectionDAO();
		
		try{
			$collection = $cdao->getCollection($userId);
			if($collection == null){
				return true;
			}
			
			$games = $collection->getGames();
			if($games[0] == ""){
				return true;
			}
		}
		catch(Exception $e){
			return false;
		}
		return false;
	}
}
?>
